package com.fingard.dsp.bank.directbank.boc01;

import java.util.Calendar;
import java.util.Date;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.ITransaction;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7515TodayTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.RetAtsTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.detail.RetAtsTransDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import org.springframework.stereotype.Component;

@Component("BOC01Transaction")
public class BOC01Transaction extends BOC01Base implements ITransaction {

    /**
     * 历史明细查询
     * @param p_req7516
     * @return
     * @throws Exception
     */
    //采用流处理方式
    //1、循环调用readRecord()读取一个请求明细，然后写入发银行的XML对象
    //2、发银行
    //3、循环调用XmlTextReader.read()读取一个银行返回节点，赋值返回ATS的明细对象，
    //   然后调用writeRetDetail()，写入返回ATS的明细
    @Override
    public RetAtsTrans d_7516_HisTrans(Req7516HisTrans p_req7516) throws Exception {
        if (StringHelper.hasAnyChar(p_req7516.swiftCode) && !swiftcodeFlag.equals(p_req7516.swiftCode.substring(0, 6))) {
            return this.getBankConfig().getValueAsBool("useb2e0220") ? this.d_7516_HisTrans_b2e0220(p_req7516) : this.d_7516_HisTrans_b2e0040(p_req7516);
        } else {
            return d_7516_HisTrans_trncod(p_req7516);
        }
    }

    /**
     * 境外中行
     *
     * @param p_req7516
     * @return
     * @throws Exception
     */
    public RetAtsTrans d_7516_HisTrans_b2e0220(Req7516HisTrans p_req7516) throws Exception {
        RetAtsTrans retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
        retAtsTrans.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";
        try {
            //起始日期
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());
            //结束日期
            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());

            int tmpIntDateFrom = 0;
            int tmpIntDateTo = 0;
            while (tmpIntDateFrom <= tmpIntDateTo && StringHelper.isNullOrEmpty(tmpRespCode)) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                //当是跨月查询时，先查询起始日期到月末日期记录，再查询月末后一天日期到结束日期记录
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {
                    tmpClndrStepTo.set(Calendar.DAY_OF_MONTH, tmpClndrStepTo.getActualMaximum(Calendar.DAY_OF_MONTH));
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }
                int tmpNowReadStart = 1;//起始笔数
                int tmpNowReadNum = 20;//本次返回笔数
                int tmpNowReadTotal = 20;//每次查询数
                while (tmpNowReadNum == tmpNowReadTotal) {
                    int qryTotal = 0;//实际查询数
                    //======拼接报文======
                    BOC01Header bankHeader = new BOC01Header();
                    bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
                    bankHeader.trncod = "b2e0220";//交易代码
                    XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                    writeCommonHeader2(xmlWriter, bankHeader);
                    xmlWriter.writeStartElement("trn-b2e0220-rq");
                    xmlWriter.writeStartElement("b2e0220-rq");
                    String areaCode = getBankConfig().getMapKeyByValue("areaMapping", p_req7516.actArea);
                    areaCode = StringHelper.hasAnyChar(areaCode) ? areaCode : p_req7516.actArea;
                    xmlWriter.writeElementString("ibknum", areaCode);
                    xmlWriter.writeElementString("actacn", p_req7516.actNum);
                    if ("7515".equals(reqHeader.transType)) {//2001当日、2002历史
                        xmlWriter.writeElementString("type", "2001");
                    } else {
                        xmlWriter.writeElementString("type", "2002");
                    }
                    xmlWriter.writeStartElement("datescope");
                    xmlWriter.writeElementString("from", Format.Date8Format.format(tmpCalendarFrom.getTime()));
                    xmlWriter.writeElementString("to", Format.Date8Format.format(tmpClndrStepTo.getTime()));
                    xmlWriter.writeEndElement();
                    xmlWriter.writeStartElement("amountscope");
                    xmlWriter.writeElementClosed("from");
                    xmlWriter.writeElementClosed("to");
                    xmlWriter.writeEndElement();
                    xmlWriter.writeElementString("begnum", tmpNowReadStart + "");//查询起始位置
                    xmlWriter.writeElementString("recnum", tmpNowReadTotal + "");//查询记录数
                    xmlWriter.writeElementString("direction", "A");//A全部
                    xmlWriter.writeElementClosed("thract");//对方账号
                    xmlWriter.writeEndDocument();
                    //======拼接报文======
                    //发送请求报文
                    String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());

                    //测试
                    //String[] tmpStrRet=new String[]{"",FileHelper.readFileText("d:\\boc03.xml","utf-8")};

                    //处理响应
                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg = new StringBuilder();
                        XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                        if (tmpBkReader != null) {
                            String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0220-rs/status/rspcod");
                            String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0220-rs/status/rspmsg");
                            if (isActiveRetCode(tmprspcod)) {
                                //B001,成功 B002,成功，未完 B003，交易数为0；
                                if ("B028".equals(tmprspcod) || "B003".equals(tmprspcod)) {
                                    break;
                                }
                                //本次返回笔数
                                if (StringHelper.hasAnyChar(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0220-rs/totalnum"))) {
                                    qryTotal = Integer.parseInt(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0220-rs/totalnum"));
                                }
                                //起始笔数
                                tmpNowReadStart += qryTotal;
                                while (tmpBkReader.read("/bocb2e/trans/trn-b2e0220-rs/b2e0220-rs")) {
                                    if ("B001".equals(tmpBkReader.readedXElement.getSingleText("status/rspcod"))) {
                                        RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                        tmpRetDetail.actArea = p_req7516.actArea;
                                        tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("fractn/actacn");//付款账号
                                        if (StringHelper.isNullOrEmpty(tmpRetDetail.actNum)) {
                                            tmpRetDetail.actNum = p_req7516.actNum;
                                        }
                                        String recAct = tmpBkReader.readedXElement.getSingleText("toactn/actacn");
                                        if (StringHelper.isNullOrEmpty(recAct)) {
                                            recAct = tmpBkReader.readedXElement.getSingleText("toactn/ibanno");
                                        }
                                        tmpRetDetail.recAccNum = recAct;//收方银行账号
                                        tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("toactn/toname");//收方账户名称
                                        tmpRetDetail.recAccBank = tmpBkReader.readedXElement.getSingleText("toactn/tobank");//收方银行
                                        tmpRetDetail.tranDate = DateHelper.convertD8toD10(tmpBkReader.readedXElement.getSingleText("txndate"));//交易日期
                                        tmpRetDetail.tranTime = tmpRetDetail.tranDate + " " + tmpBkReader.readedXElement.getSingleText("txntime");//交易时间
                                        tmpRetDetail.valueDate = DateHelper.convertD8toD10(tmpBkReader.readedXElement.getSingleText("valdat"));//起息日
                                        tmpRetDetail.tranAmt = tmpBkReader.readedXElement.getSingleText("txnamt");//交易金额 无符号位，不做负号判断
                                        String cdFlag = tmpBkReader.readedXElement.getSingleText("direction");//借贷标记
                                        tmpRetDetail.cdFlag = "D".equals(cdFlag) ? "1" : ("C".equals(cdFlag) ? "2" : "");
                                        tmpRetDetail.accBal = tmpBkReader.readedXElement.getSingleText("acctbal").replace("+", "");//账户余额
                                        tmpRetDetail.usage = tmpBkReader.readedXElement.getSingleText("useinfo");//用途
                                        tmpRetDetail.comment = tmpBkReader.readedXElement.getSingleText("furinfo");//备注
                                        tmpRetDetail.abstr = pickupAbstr(tmpBkReader.readedXElement.getSingleText("useinfo"), tmpBkReader.readedXElement.getSingleText("furinfo"));
                                        tmpRetDetail.originator = tmpBkReader.readedXElement.getSingleText("vchnum");//交易流水号
                                        tmpRetDetail.receiptNo = tmpBkReader.readedXElement.getSingleText("vchnum");//交易流水号
                                        tmpRetDetail.busRef = tmpBkReader.readedXElement.getSingleText("vchnum");//交易流水号
                                        tmpRetDetail.askNumber = tmpBkReader.readedXElement.getSingleText("vchnum");//交易流水号
                                        tmpRetDetail.cur = convertCurToATS(tmpBkReader.readedXElement.getSingleText("trncur"));//币种
                                        tmpRetDetail.busType = tmpBkReader.readedXElement.getSingleText("transtype");//新业务类型
                                        retAtsTrans.writeRetDetail(tmpRetDetail);
                                    }
                                }
                            } else {
                                tmpRespCode = "-1";
                                tmpRespInfo = tmprspmsg;
                                break;
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpSbMsg.toString();
                            break;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpStrRet[1];
                        break;
                    }
                    tmpNowReadNum = qryTotal;
                }
                tmpCalendarFrom = tmpClndrStepTo;
                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpCalendarFrom.getTime()));
                tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()));
            }
        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            ex.printStackTrace();
            WriteBankLogLn("查询明细异常:" + ex);
        }
        if ("-1".equals(tmpRespCode)) {
            retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
            retAtsTrans.writeStart();//写返回ATS的统一头部信息
            retAtsTrans.writeRespCode(tmpRespCode);
            retAtsTrans.writeRespInfo(tmpRespInfo);
        } else if (retAtsTrans.getWrittenRdCount() == 0) {
            retAtsTrans.writeRespInfo("交易为空");
            retAtsTrans.writeRespCode("0");
        }
        retAtsTrans.writeEnd();
        return retAtsTrans;
    }


    //ATSES-21084 境外中行今日/历史明细查询接口变更 --范天星/2020/01/17
    private RetAtsTrans d_7516_HisTrans_b2e0040(Req7516HisTrans p_req7516) throws Exception {
        RetAtsTrans retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
        retAtsTrans.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";

        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());
            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());
            int tmpIntDateFrom = 0;

            for (int tmpIntDateTo = 0; tmpIntDateFrom <= tmpIntDateTo && StringHelper.isNullOrEmpty(tmpRespCode); tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()))) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {
                    tmpClndrStepTo.set(5, tmpClndrStepTo.getActualMaximum(5));
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }

                BOC01Header bankHeader = new BOC01Header();
                bankHeader.trnid = this.getQryTransID();
                bankHeader.trncod = "b2e0040";
                XmlTextWriter xmlWriter = new XmlTextWriter();
                this.writeCommonHeader2(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("trn-b2e0040-rq");
                xmlWriter.writeStartElement("b2e0040-rq");
                String areaCode = this.getBankConfig().getMapKeyByValue("areaMapping", p_req7516.actArea);
                areaCode = StringHelper.hasAnyChar(areaCode) ? areaCode : p_req7516.actArea;
                xmlWriter.writeElementString("ibknum", areaCode);
                xmlWriter.writeElementString("actacn", p_req7516.actNum);
                xmlWriter.writeStartElement("datescope");
                xmlWriter.writeElementString("from", Format.Date8Format.format(tmpCalendarFrom.getTime()));
                xmlWriter.writeElementString("to", Format.Date8Format.format(tmpClndrStepTo.getTime()));
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                String[] tmpStrRet = this.sendToBank(xmlWriter.toXmlString());
                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = this.loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0040-rs/status/rspcod");
                        String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0040-rs/status/rspmsg");
                        if (this.isActiveRetCode(tmprspcod)) {
                            while (tmpBkReader.read("/bocb2e/trans/trn-b2e0040-rs/b2e0040-rs")) {
                                if ("B001".equals(tmpBkReader.readedXElement.getSingleText("status/rspcod"))) {
                                    RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                    tmpRetDetail.actArea = p_req7516.actArea;
                                    String transAmt = tmpBkReader.readedXElement.getSingleText("detail/txnamt");
                                    String cdFlag;
                                    if (Integer.parseInt(transAmt) < 0) {
                                        cdFlag = "1";
                                        tmpRetDetail.tranAmt = transAmt.substring(1, transAmt.length());
                                    } else {
                                        cdFlag = "2";
                                        tmpRetDetail.tranAmt = transAmt;
                                    }

                                    tmpRetDetail.cdFlag = cdFlag;
                                    tmpRetDetail.accBal = tmpBkReader.readedXElement.getSingleText("detail/bokbal");
                                    tmpRetDetail.cur = this.convertCurToATS(tmpBkReader.readedXElement.getSingleText("account/trncur"));
                                    tmpRetDetail.originator = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                    tmpRetDetail.receiptNo = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                    tmpRetDetail.busRef = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                    tmpRetDetail.askNumber = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                    tmpRetDetail.comment = tmpBkReader.readedXElement.getSingleText("detail/furinfo");
                                    tmpRetDetail.abstr = pickupAbstr(new String[]{tmpBkReader.readedXElement.getSingleText("useinfo"), tmpBkReader.readedXElement.getSingleText("actacn/furinfo")});
                                    tmpRetDetail.tranTime = tmpBkReader.readedXElement.getSingleText("detail/trfdate") + " " + tmpRetDetail.tranTime;
                                    tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("account/actacn");
                                    tmpRetDetail.usage = tmpBkReader.readedXElement.getSingleText("actacn/furinfo");
                                    retAtsTrans.writeRetDetail(tmpRetDetail);
                                }
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmprspmsg;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpStrRet[1];
                }

                tmpCalendarFrom = tmpClndrStepTo;
                tmpClndrStepTo.add(5, 1);
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpClndrStepTo.getTime()));
            }
        } catch (Exception var21) {
            tmpRespCode = "-1";
            tmpRespInfo = var21.getMessage();
            var21.printStackTrace();
            this.WriteBankLogLn("查询明细异常:" + var21);
        }

        if ("-1".equals(tmpRespCode)) {
            retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
            retAtsTrans.writeStart();
            retAtsTrans.writeRespCode(tmpRespCode);
            retAtsTrans.writeRespInfo(tmpRespInfo);
        } else if (retAtsTrans.getWrittenRdCount() == 0) {
            retAtsTrans.writeRespInfo("交易为空");
            retAtsTrans.writeRespCode("0");
        }

        retAtsTrans.writeEnd();
        return retAtsTrans;
    }

    /**
     * 境内中行
     *
     * @param p_req7516
     * @return
     * @throws Exception
     */
    public RetAtsTrans d_7516_HisTrans_trncod(Req7516HisTrans p_req7516) throws Exception {
        //历史明细查询返回ATS的对象
        RetAtsTrans retAts = new RetAtsTrans(p_req7516.reqHeader);
        String trncod = getBankConfig().getValueAsString("trncod7516");
        if (trncod != null) {
            if ("b2e0011".equals(trncod)) {
                return d_7516_Getb2e0011Transactions(p_req7516);
            } else if ("b2e0035".equals(trncod)) {
                return d_7516_Getb2e0035Transactions(p_req7516);
            } else {
                retAts.writeRespCode("0");
                retAts.writeRespInfo("关于交易代码配置信息有误");
                return retAts;
            }
        } else {
            retAts.writeRespCode("0");
            retAts.writeRespInfo("关于交易代码配置信息为空");
            return retAts;
        }
    }

    public RetAtsTrans d_7516_Getb2e0011Transactions(Req7516HisTrans p_req7516) throws Exception {
        //历史明细查询返回ATS的对象
        RetAtsTrans retAts = new RetAtsTrans(p_req7516.reqHeader);
        String tmpRespCode = "";
        String tmpRespInfo = "";
        retAts.writeStart();//写返回ATS的统一头部信息
        try {
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());
            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());
            //int qryCount=0;
            int tmpIntDateFrom = 0;
            int tmpIntDateTo = 0;
            //按自然月循环查询
            while (tmpIntDateFrom <= tmpIntDateTo && tmpRespCode.length() == 0) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                //判断是否跨月
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {
                    //跨月则设置为月末
                    tmpClndrStepTo.set(Calendar.DAY_OF_MONTH, tmpClndrStepTo.getActualMaximum(Calendar.DAY_OF_MONTH));
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }
                int tmpBegnum = -2;//起始数
                int tmpTotalRdNum = -1;//返回总数
                int tmpReadNum = 0;//已查询的总数
                while (tmpBegnum <= tmpTotalRdNum && tmpRespCode.length() == 0) {//分页查询
                    if (tmpBegnum < 0) {
                        tmpBegnum = 1;
                    }
                    int tmpPageRdNum = 0;
                    //qryCount++;
                    BOC01Header bankHeader = new BOC01Header();
                    bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
                    bankHeader.trncod = "b2e0011";//交易代码
                    XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                    //写入通用的头部节点，<trans>之后
                    writeCommonHeader(xmlWriter, bankHeader);
                    /*
        <trn-b2e0011-rq>
	      <b2e0011-rq>
	        <ibknum></ibknum>
	        <actacn></actacn>
	        <datescope>
	          <from></from>
	          <to></to>
	        </datescope>
	        <typescope>0</typescope>
	      </b2e0011-rq>
	    </trn-b2e0011-rq>
					 * */
                    xmlWriter.writeStartElement("trn-b2e0011-rq");
                    xmlWriter.writeStartElement("b2e0011-rq");
                    String areaCode = getBankConfig().getMapKeyByValue("areaMapping", p_req7516.actArea);
                    areaCode = StringHelper.hasAnyChar(areaCode) ? areaCode : p_req7516.actArea;
                    xmlWriter.writeElementString("ibknum", areaCode);
                    xmlWriter.writeElementString("actacn", p_req7516.actNum);
                    xmlWriter.writeStartElement("datescope");
                    xmlWriter.writeElementString("from", Format.Date8Format.format(tmpCalendarFrom.getTime()));
                    xmlWriter.writeElementString("to", Format.Date8Format.format(tmpClndrStepTo.getTime()));
                    xmlWriter.writeEndElement();
                    xmlWriter.writeElementString("typescope", "0");
                    xmlWriter.writeEndDocument();
                    xmlWriter.writeEndDocument();
                    String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                    XmlTextReader tmpBkReader;
                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg = new StringBuilder();
                        tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                        if (tmpBkReader != null) {
                            String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0011-rs/status/rspcod");
                            String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0011-rs/status/rspmsg");
                            if (isActiveRetCode(tmprspcod)) {
                                //B028 账户无交易
                                //B003 交易数为0
                                if ("B028".equals(tmprspcod) || "B003".equals(tmprspcod)) {
                                    break;
                                }
                                String repCode = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0011-rs/b2e0011-rs/status/rspcod");
                                if ("B028".equals(repCode) || "B003".equals(repCode)) {
                                    break;
                                }
                                //<totalnum> 本次返回笔数
                                // tmpPageRdNum = Integer.parseInt(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0011-rs/totalnum"));
                                //<notenum> 总记录数
                                // tmpTotalRdNum = Integer.parseInt(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0011-rs/notenum"));
                                //tmpAtsCur = convertCurToATS(tmpCurrType);
                                //循环数
                                int count = 0;
                                while (tmpBkReader.read("/bocb2e/trans/trn-b2e0011-rs/b2e0011-rs")) {
                                    //校验是否正常返回
                                    String eachRspcod = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                                    if (getBankConfig().getValueAsBool("continueTrans")) {
                                        if (StringHelper.hasAnyChar(tmpBkReader.readedXElement.getSingleText("mactacn"))) {
                                            count++;
                                            continue;
                                        }
                                    }
                                    RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                    tmpRetDetail.actArea = tmpBkReader.readedXElement.getSingleText("account/ibknum");
                                    if ("B001".equals(eachRspcod)) {
                                        String cdflag = tmpBkReader.readedXElement.getSingleText("cdflag");//借贷标记：D-借  C-贷
                                        if (cdflag != null) {
                                            if ("D".equals(cdflag)) {//借的情况
                                                tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("account/actacn");//对方账号
                                                tmpRetDetail.tranAmt = tmpBkReader.readedXElement.getSingleText("txnamt");//对方账号
                                                String eachTranstype = tmpBkReader.readedXElement.getSingleText("rvslbl");
                                                if ("*".equals(eachTranstype)) {
                                                    tmpRetDetail.cdFlag = "2";
                                                } else {
                                                    tmpRetDetail.cdFlag = "1";
                                                }
                                                tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("thract");
                                            } else if ("C".equals(cdflag)) {
                                                tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("account/actacn");//对方账号
                                                tmpRetDetail.tranAmt = tmpBkReader.readedXElement.getSingleText("txnamt");//对方账号
                                                String eachTranstype = tmpBkReader.readedXElement.getSingleText("rvslbl");
                                                if ("*".equals(eachTranstype)) {
                                                    tmpRetDetail.cdFlag = "1";
                                                } else {
                                                    tmpRetDetail.cdFlag = "2";
                                                }
                                                tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("thract");
                                            } else {
                                                throw new Exception("cdflag无效：" + cdflag);
                                            }
                                            // xln_tmpToAddChild.SelectSingleNode("descendant::RecAccName").InnerText = tmpOneRecord.SelectSingleNode("descendant::thractname").InnerText;
                                            tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("thractname");

                                        }
                                        //xln_tmpToAddChild.SelectSingleNode("descendant::AccBal").InnerText = tmpOneRecord.SelectSingleNode("descendant::avabal").InnerText;
                                        tmpRetDetail.accBal = tmpBkReader.readedXElement.getSingleText("avabal");
                                        //xln_tmpToAddChild.SelectSingleNode("descendant::PostTimestamp").InnerText = tmpOneRecord.SelectSingleNode("descendant::stmtime").InnerText;
                                        //tmpRetDetail.postTimestamp=tmpBkReader.readedXElement.getSingleText("stmtime");
                                    }
                                    //入账日期
                                    String eachDate = "";
                                    if (tmpBkReader.readedXElement.getSingleText("stmdate") != null) {
                                        StringBuilder stmdate = new StringBuilder(tmpBkReader.readedXElement.getSingleText("stmdate"));
                                        if (tmpBkReader.readedXElement.getSingleText("stmdate").length() == 8) {
                                            tmpRetDetail.tranDate = stmdate.insert(4, "-").insert(7, "-").toString();
                                        } else {
                                            tmpRetDetail.tranDate = stmdate.toString();

                                        }
                                        String tranTime = tmpBkReader.readedXElement.getSingleText("stmtime");
                                        if (!StringHelper.isNullOrEmpty(tmpBkReader.readedXElement.getSingleText("stmtime"))) {
                                            eachDate = stmdate.toString() + " " + tranTime.substring(0, 2) + ":" + tranTime.substring(2, 4) + ":" + tranTime.substring(4, 6);

                                        }
                                    }
                                    if (tmpRetDetail.tranDate.trim().length() == 0) {
                                        tmpRetDetail.tranDate = Format.Date8Format.format(new Date());
                                    }
                                    //起息日期
                                    if (tmpBkReader.readedXElement.getSingleText("valdat") != null) {
                                        StringBuilder stmtime = new StringBuilder(tmpBkReader.readedXElement.getSingleText("valdat"));
                                        if (tmpBkReader.readedXElement.getSingleText("valdat").length() == 8) {
                                            tmpRetDetail.valueDate = stmtime.insert(4, "-").insert(7, "-").toString();
                                        } else {
                                            tmpRetDetail.valueDate = stmtime.toString();

                                        }
                                    }
                                    if (tmpRetDetail.valueDate.trim().length() == 0) {
                                        tmpRetDetail.valueDate = Format.Date8Format.format(new Date());
                                    }
                                    //tmpRetDetail.tranDate = Format.Date10Format.format(eachDate);
                                    tmpRetDetail.tranTime = eachDate;
                                    if (!StringHelper.isNullOrEmpty(tmpBkReader.readedXElement.getSingleText("valdat"))) {
                                        Date valueDate = Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("valdat"));//起息日期YYYYMMDD
                                        tmpRetDetail.valueDate = Format.Date10Format.format(valueDate);
                                    }

                                    tmpRetDetail.billNum = tmpBkReader.readedXElement.getSingleText("vchnum");

                                    tmpRetDetail.abstr = pickupAbstr(tmpBkReader.readedXElement.getSingleText("useinfo"), tmpBkReader.readedXElement.getSingleText("furinfo"));


                                    if (StringHelper.isNullOrEmpty(tmpRetDetail.actNum)) {
                                        tmpRetDetail.actNum = p_req7516.actNum;
                                    }
                                    tmpRetDetail.tranAmt = tmpBkReader.readedXElement.getSingleText("txnamt").replace("-", "");  //<txnamt>	金额（非空）
                                    tmpRetDetail.usage = tmpBkReader.readedXElement.getSingleText("furinfo");
                                    tmpRetDetail.originator = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    tmpRetDetail.receiptNo = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    tmpRetDetail.busRef = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    String furinfo = tmpBkReader.readedXElement.getSingleText("furinfo");
                                    if (StringHelper.hasAnyChar(furinfo) && (
                                            furinfo.toLowerCase().contains("obss")
                                                    || furinfo.toLowerCase().contains("hvps")
                                                    || furinfo.toLowerCase().contains("beps"))) {
                                        tmpRetDetail.comment = tmpBkReader.readedXElement.getSingleTextNotNull("useinfo");
                                    } else {
                                        tmpRetDetail.comment = furinfo;
                                    }
                                    //响应中英的要求，当等于41手续费的时候对账码无值。
//                                    if ("41".equals(eachTranstype)) {
//                                        tmpRetDetail.abstr = "";
//                                    }
                                    nodeAnalysic(tmpBkReader.readedXElement, tmpRetDetail, getCharset());
                                    retAts.writeRetDetail(tmpRetDetail);
                                    count++;
                                }
                                tmpReadNum += tmpPageRdNum;//统计已查询的笔数

                            } else {
                                tmpRespCode = "-1";
                                if (StringHelper.isNullOrEmpty(tmprspmsg)) {
                                    tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                                }
                                tmpRespInfo = tmprspmsg;
                                break;
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpSbMsg.toString();
                            break;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpStrRet[1];
                        break;
                    }
                    if (tmpPageRdNum == 0) {
                        break;
                    }
                }
                tmpCalendarFrom = tmpClndrStepTo;
                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpCalendarFrom.getTime()));
                tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()));
            }
        } catch (Exception e) {
            tmpRespCode = "-1";
            tmpRespInfo = e.getMessage();
            e.printStackTrace();
        }
        if ("-1".equals(tmpRespCode)) {
            retAts = new RetAtsTrans(p_req7516.reqHeader);
            retAts.writeStart();//写返回ATS的统一头部信息
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            retAts.writeRespCode("0");
            retAts.writeRespInfo("交易为空");
        }
        retAts.writeEnd();
        return retAts;
    }

    public RetAtsTrans d_7516_Getb2e0035Transactions(Req7516HisTrans p_req7516) throws Exception {
        //历史明细查询返回ATS的对象
        RetAtsTrans retAts = new RetAtsTrans(p_req7516.reqHeader);
        String tmpRespCode = "";
        String tmpRespInfo = "";
        retAts.writeStart();//写返回ATS的统一头部信息
        try {

            //Date tmpDateFrom = p_req7516.getDateFrom();
            //Date tmpDateTo = p_req7516.getDateTo();
            //tmpClndrStepTo.get(Calendar.MONTH) MONTH是从0开始编的，意味着0是1月，11是12月
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());

            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());

            //int qryCount=0;
            int tmpIntDateFrom = 0;
            int tmpIntDateTo = 0;
            //按自然月循环查询
            while (tmpIntDateFrom <= tmpIntDateTo && tmpRespCode.length() == 0) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                //判断是否跨月
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {
                    //跨月则设置为月末
                    tmpClndrStepTo.set(Calendar.DAY_OF_MONTH, tmpClndrStepTo.getActualMaximum(Calendar.DAY_OF_MONTH));
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }

                int tmpBegnum = -2;//起始数
                int tmpTotalRdNum = -1;//返回总数
                int tmpReadNum = 0;//已查询的总数
                while (tmpBegnum <= tmpTotalRdNum && tmpRespCode.length() == 0) {//分页查询
                    if (tmpBegnum < 0) {
                        tmpBegnum = 1;
                    }
                    int tmpPageRdNum = 0;
                    //qryCount++;
                    BOC01Header bankHeader = new BOC01Header();
                    bankHeader.trnid = getQryTransID();//报文编号 字母数字串 0-12位
                    bankHeader.trncod = "b2e0035";//交易代码
                    XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                    //写入通用的头部节点，<trans>之后
                    writeCommonHeader(xmlWriter, bankHeader);
                    /*
        <trn-b2e0035-rq>
	      <b2e0035-rq>
	        <ibknum></ibknum>
	        <actacn></actacn>
	        <type>2002</type>
	        <datescope>
	          <from></from>
	          <to></to>
	        </datescope>
	        <amountscope>
	          <from></from>
	          <to></to>
	        </amountscope>
	        <begnum>1</begnum>
	        <recnum>50</recnum>
	        <direction>0</direction>
	      </b2e0035-rq>
	    </trn-b2e0035-rq>
					 * */
                    xmlWriter.writeStartElement("trn-b2e0035-rq");
                    xmlWriter.writeStartElement("b2e0035-rq");
                    String areaCode = getBankConfig().getMapKeyByValue("areaMapping", p_req7516.actArea);
                    areaCode = StringHelper.hasAnyChar(areaCode) ? areaCode : p_req7516.actArea;
                    xmlWriter.writeElementString("ibknum", areaCode);
                    xmlWriter.writeElementString("actacn", p_req7516.actNum);
                    if ("7515".equals(reqHeader.transType)) {
                        xmlWriter.writeElementString("type", "2001");
                    } else {
                        xmlWriter.writeElementString("type", "2002");
                    }
                    xmlWriter.writeStartElement("datescope");
                    xmlWriter.writeElementString("from", Format.Date8Format.format(tmpCalendarFrom.getTime()));
                    xmlWriter.writeElementString("to", Format.Date8Format.format(tmpClndrStepTo.getTime()));
                    xmlWriter.writeEndElement();
                    xmlWriter.writeStartElement("amountscope");
                    xmlWriter.writeElementClosed("from");
                    xmlWriter.writeElementClosed("to");
                    xmlWriter.writeEndElement();
                    xmlWriter.writeElementString("begnum", String.valueOf(tmpBegnum));
                    xmlWriter.writeElementString("recnum", "50");
                    xmlWriter.writeElementString("direction", "0");
                    xmlWriter.writeEndDocument();

                    String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                    XmlTextReader tmpBkReader;

                    //String tmpAccNo = "";
                    //String tmpCurrType = "";
                    //String tmpAtsCur = "";
                    if (tmpStrRet[0].length() == 0) {
                        StringBuilder tmpSbMsg = new StringBuilder();
                        tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                        if (tmpBkReader != null) {
                            String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0035-rs/status/rspcod");
                            String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0035-rs/status/rspmsg");
                            if (isActiveRetCode(tmprspcod)) {
                                //B028 账户无交易
                                //B003 交易数为0
                                if ("B028".equals(tmprspcod) || "B003".equals(tmprspcod)) {
                                    break;
                                }
                                //<totalnum> 本次返回笔数
                                tmpPageRdNum = Integer.parseInt(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0035-rs/totalnum"));
                                //<notenum> 总记录数
                                tmpTotalRdNum = Integer.parseInt(tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0035-rs/notenum"));
                                //tmpAtsCur = convertCurToATS(tmpCurrType);
                                //循环数
                                int count = 0;
                                while (tmpBkReader.read("/bocb2e/trans/trn-b2e0035-rs/b2e0035-rs")) {
                                    if (getBankConfig().getValueAsBool("continueTrans")) {
                                        if (StringHelper.hasAnyChar(tmpBkReader.readedXElement.getSingleText("mactacn"))) {
                                            count++;
                                            continue;
                                        }
                                    }

                                    RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                    String eachRspcod = tmpBkReader.readedXElement.getSingleText("status/rspcod");
                                    if ("B001".equals(eachRspcod)) {
                                        String eachDirection = tmpBkReader.readedXElement.getSingleText("direction");//往来帐标识；1代表入账（收款），2代表出账（付款）
                                        if ("2".equals(eachDirection)) {
                                            tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("fractn/actacn");
                                            if (tmpBkReader.readedXElement.getSingleText("txnamt").trim().startsWith("-")) {
                                                tmpRetDetail.cdFlag = "2";//收款
                                            } else {
                                                tmpRetDetail.cdFlag = "1";//付款
                                            }
                                            tmpRetDetail.recAccNum = tmpBkReader.readedXElement.getSingleText("toactn/actacn");//对方账号
                                            tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("toactn/toname");//对方户名
                                            tmpRetDetail.recAccBank = tmpBkReader.readedXElement.getSingleText("toactn/tobank");
                                        } else if ("1".equals(eachDirection)) {
                                            tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("toactn/actacn");
                                            if (tmpBkReader.readedXElement.getSingleText("txnamt").trim().startsWith("-")) {
                                                tmpRetDetail.cdFlag = "1";//付款
                                            } else {
                                                tmpRetDetail.cdFlag = "2";//收款
                                            }
                                            tmpRetDetail.recAccNum = tmpBkReader.readedXElement.getSingleText("fractn/actacn");//对方账号
                                            tmpRetDetail.recAccName = tmpBkReader.readedXElement.getSingleText("fractn/acntname");//对方户名
                                            tmpRetDetail.recAccBank = tmpBkReader.readedXElement.getSingleText("fractn/ibkname");//对方行别
                                        } else {
                                            throw new Exception("direction无效：" + eachDirection);
                                        }
                                    }
                                    if (StringHelper.isNullOrEmpty(tmpRetDetail.actNum)) {
                                        tmpRetDetail.actNum = p_req7516.actNum;
                                    }
                                    tmpRetDetail.tranAmt = tmpBkReader.readedXElement.getSingleText("txnamt").replace("-", "");  //<txnamt>	金额（非空）
                                    //<transtype>11</transtype>  ，代表冲正
                                    String eachTranstype = tmpBkReader.readedXElement.getSingleText("transtype");
                                    if ("11".equals(eachTranstype)) {
                                        if ("2".equals(tmpRetDetail.cdFlag)) {
                                            tmpRetDetail.cdFlag = "1";
                                        } else if ("1".equals(tmpRetDetail.cdFlag)) {
                                            tmpRetDetail.cdFlag = "2";
                                        }
                                    }
                                    tmpRetDetail.accBal = tmpBkReader.readedXElement.getSingleText("acctbal");   //<acctbal>	交易后余额
                                    //<txndate>	交易日期 YYYYMMDD（非空）
                                    //<txntime>	交易时间 HH24MISS
                                    Date eachDate = Format.DateTime14Format.parse(tmpBkReader.readedXElement.getSingleText("txndate") + tmpBkReader.readedXElement.getSingleText("txntime"));
                                    tmpRetDetail.tranDate = Format.Date10Format.format(eachDate);
                                    tmpRetDetail.tranTime = Format.DateTimeFormat.format(eachDate);
                                    tmpRetDetail.postTimestamp = Format.DateTime14Format.format(eachDate);
                                    if (!StringHelper.isNullOrEmpty(tmpBkReader.readedXElement.getSingleText("valdat"))) {
                                        eachDate = Format.Date8Format.parse(tmpBkReader.readedXElement.getSingleText("valdat"));//起息日期YYYYMMDD
                                        tmpRetDetail.valueDate = Format.Date10Format.format(eachDate);
                                    }
                                    //支付时送银行的furinfo字段 <furinfo>资金调拨＋CC000025J6</furinfo>
                                    String usage_abstr = tmpBkReader.readedXElement.getSingleText("useinfo");
                                    if (StringHelper.isNullOrEmpty(usage_abstr)) {
                                        tmpRetDetail.usage = tmpBkReader.readedXElement.getSingleText("furinfo");
                                        tmpRetDetail.abstr = "";
                                    } else {
                                        //判断是否为资金系统产生的交易，不是则没有abstr
                                        if (usage_abstr.contains("＋")){
                                            tmpRetDetail.usage = usage_abstr.split("＋")[0];
                                            tmpRetDetail.abstr = usage_abstr.split("＋")[1];
                                        } else {
                                            tmpRetDetail.usage = usage_abstr;
                                            tmpRetDetail.abstr = "";
                                        }
                                    }
//                                    tmpRetDetail.abstr = pickupAbstr(tmpBkReader.readedXElement.getSingleText("useinfo"), tmpBkReader.readedXElement.getSingleText("furinfo"));
                                    tmpRetDetail.payCode = tmpRetDetail.usage;
                                    tmpRetDetail.originator = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    tmpRetDetail.receiptNo = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    tmpRetDetail.busRef = tmpBkReader.readedXElement.getSingleText("vchnum");
                                    String bustype = tmpBkReader.readedXElement.getSingleText("bustype");
                                    if (!StringHelper.isNullOrEmpty(bustype)) {
                                        tmpRetDetail.busType = getBankConfig().getMapValueByKey("busType", bustype);
                                    }
//                                    F://A:OBSS019733010171GIRO000000000LIZ//U://R:
//                                    String interInfo = tmpBkReader.readedXElement.getSingleText("interinfo");
//                                    if(StringHelper.hasAnyChar(interInfo)){
//                                        String[] interArr = interInfo.split("//");
//                                        if(interArr.length==4) {
//                                            Arrays.sort(interArr);
//                                            if (interArr[1].length()>2||interArr[3].length()>2){
//                                                tmpRetDetail.comment =interArr[1].substring(2)+" "+ interArr[3].substring(2);
//                                            }else if(interArr[0].length()>2){
//                                                if(isChineseCharacter(interArr[0].substring(2))){
//                                                    tmpRetDetail.comment =interArr[0].substring(2);
//                                                }
//                                            }
//                                        }
//                                    }
                                    String furinfo = tmpBkReader.readedXElement.getSingleText("furinfo");
                                    if (StringHelper.hasAnyChar(furinfo) && (
                                            furinfo.toLowerCase().contains("obss")
                                                    || furinfo.toLowerCase().contains("hvps")
                                                    || furinfo.toLowerCase().contains("beps"))) {
                                        tmpRetDetail.comment = tmpBkReader.readedXElement.getSingleTextNotNull("useinfo");
                                    } else {
                                        tmpRetDetail.comment = furinfo;
                                    }


                                    //响应中英的要求，当等于41手续费的时候对账码无值。
                                    if ("41".equals(eachTranstype)) {
                                        tmpRetDetail.abstr = "";
                                    }

                                    String vouchtp = tmpBkReader.readedXElement.getSingleText("vouchtp");
                                    if (!StringHelper.isNullOrEmpty(bustype)) {
                                        tmpRetDetail.billType = getBankConfig().getMapValueByKey("vouchtp", vouchtp);
                                    }
                                    tmpRetDetail.billNum = tmpBkReader.readedXElement.getSingleText("vouchnum");

                                    tmpRetDetail.mactibkn = tmpBkReader.readedXElement.getSingleText("mactibkn");
                                    tmpRetDetail.mactacn = tmpBkReader.readedXElement.getSingleText("mactacn");
                                    tmpRetDetail.mactname = tmpBkReader.readedXElement.getSingleText("mactname");
                                    tmpRetDetail.mactbank = tmpBkReader.readedXElement.getSingleText("mactbank");
                                    nodeAnalysic(tmpBkReader.readedXElement, tmpRetDetail, getCharset());
                                    retAts.writeRetDetail(tmpRetDetail);
                                    count++;
                                }
                                if (tmpPageRdNum != count) {
                                    throw new Exception("循环记录数与返回笔数不一致");
                                }
                                tmpReadNum += tmpPageRdNum;//统计已查询的笔数

                                tmpBegnum = tmpBegnum + tmpPageRdNum;//起始数

                                if (tmpBegnum > tmpTotalRdNum) {//起始数>返回总数
                                    if (tmpReadNum != tmpTotalRdNum) {
                                        throw new Exception("银行返回的总笔数" + tmpTotalRdNum + "与查询统计返回的总笔数" + tmpReadNum + "不相等");
                                    }
                                }
                            } else {
                                tmpRespCode = "-1";
                                if (StringHelper.isNullOrEmpty(tmprspmsg)) {
                                    tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2eerror-rs/status/rspmsg");
                                }
                                tmpRespInfo = tmprspmsg;
                                break;
                            }
                        } else {
                            tmpRespCode = "-1";
                            tmpRespInfo = tmpSbMsg.toString();
                            break;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpStrRet[1];
                        break;
                    }
                    if (tmpPageRdNum == 0) {
                        break;
                    }
                }
                tmpCalendarFrom = tmpClndrStepTo;
                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpCalendarFrom.getTime()));
                tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()));
            }
        } catch (Exception e) {
            tmpRespCode = "-1";
            tmpRespInfo = e.getMessage();
            e.printStackTrace();
        }
        if ("-1".equals(tmpRespCode)) {
            retAts = new RetAtsTrans(p_req7516.reqHeader);
            retAts.writeStart();//写返回ATS的统一头部信息
            retAts.writeRespCode(tmpRespCode);
            retAts.writeRespInfo(tmpRespInfo);
        } else if (retAts.getWrittenRdCount() == 0) {
            retAts.writeRespCode("0");
            retAts.writeRespInfo("交易为空");
        }
        retAts.writeEnd();
        return retAts;
    }

    /**
     * 当日流水查询
     * @param p_req7515
     * @return
     * @throws Exception
     */
    //当日明细查询调用历史明细查询方法
    @Override
    public RetAtsTrans d_7515_TodayTrans(Req7515TodayTrans p_req7515) throws Exception {
        //通用b2e0035
        Req7516HisTrans tmpReq7516 = new Req7516HisTrans(p_req7515.reqHeader);
        tmpReq7516.actArea = p_req7515.actArea;
        tmpReq7516.actCur = p_req7515.actCur;
        tmpReq7516.actNum = p_req7515.actNum;
        String tmpStrToday = Format.Date8Format.format(new Date());
        tmpReq7516.dateFrom = tmpStrToday;
        tmpReq7516.dateTo = tmpStrToday;
        if (StringHelper.hasAnyChar(p_req7515.swiftCode) && !swiftcodeFlag.equals(p_req7515.swiftCode.substring(0, 6))) {
            return this.getBankConfig().getValueAsBool("useb2e0220") ? this.d_7516_HisTrans_b2e0220(tmpReq7516) : this.d_7515_TodayTrans_b2e0038(tmpReq7516);
        } else {
            return d_7516_Getb2e0035Transactions(tmpReq7516);
        }
    }

    //ATSES-21084 境外中行今日/历史明细查询接口变更 --范天星/2020/01/17
    private RetAtsTrans d_7515_TodayTrans_b2e0038(Req7516HisTrans p_req7516) throws Exception {
        RetAtsTrans retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
        retAtsTrans.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";

        try {
            BOC01Header bankHeader = new BOC01Header();
            bankHeader.trnid = this.getQryTransID();
            bankHeader.trncod = "b2e0038";
            XmlTextWriter xmlWriter = new XmlTextWriter();
            this.writeCommonHeader2(xmlWriter, bankHeader);
            xmlWriter.writeStartElement("trn-b2e0038-rq");
            xmlWriter.writeStartElement("b2e0038-rq");
            String areaCode = this.getBankConfig().getMapKeyByValue("areaMapping", p_req7516.actArea);
            areaCode = StringHelper.hasAnyChar(areaCode) ? areaCode : p_req7516.actArea;
            xmlWriter.writeElementString("ibknum", areaCode);
            xmlWriter.writeElementString("actacn", p_req7516.actNum);
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
            xmlWriter.writeEndElement();
            String[] tmpStrRet = this.sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = this.loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmprspcod = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0038-rs/status/rspcod");
                    String tmprspmsg = tmpBkReader.getFirstText("/bocb2e/trans/trn-b2e0038-rs/status/rspmsg");
                    if (this.isActiveRetCode(tmprspcod)) {
                        while (tmpBkReader.read("/bocb2e/trans/trn-b2e0038-rs/b2e0038-rs")) {
                            if ("B001".equals(tmpBkReader.readedXElement.getSingleText("status/rspcod"))) {
                                RetAtsTransDetail tmpRetDetail = new RetAtsTransDetail();
                                tmpRetDetail.actArea = p_req7516.actArea;
                                String transAmt = tmpBkReader.readedXElement.getSingleText("detail/txnamt");
                                String cdFlag;
                                if (Integer.parseInt(transAmt) < 0) {
                                    cdFlag = "1";
                                    tmpRetDetail.tranAmt = transAmt.substring(1, transAmt.length());
                                } else {
                                    cdFlag = "2";
                                    tmpRetDetail.tranAmt = transAmt;
                                }

                                tmpRetDetail.cdFlag = cdFlag;
                                tmpRetDetail.cur = this.convertCurToATS(tmpBkReader.readedXElement.getSingleText("account/trncur"));
                                tmpRetDetail.originator = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                tmpRetDetail.receiptNo = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                tmpRetDetail.busRef = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                tmpRetDetail.askNumber = tmpBkReader.readedXElement.getSingleText("detail/vchset");
                                tmpRetDetail.comment = tmpBkReader.readedXElement.getSingleText("detail/furinfo");
                                tmpRetDetail.abstr = pickupAbstr(new String[]{tmpBkReader.readedXElement.getSingleText("useinfo"), tmpBkReader.readedXElement.getSingleText("actacn/furinfo")});
                                tmpRetDetail.tranTime = tmpRetDetail.tranDate + " " + tmpBkReader.readedXElement.getSingleText("detail/stmtime");
                                tmpRetDetail.actNum = tmpBkReader.readedXElement.getSingleText("account/actacn");
                                tmpRetDetail.usage = tmpBkReader.readedXElement.getSingleText("useinfo");
                                retAtsTrans.writeRetDetail(tmpRetDetail);
                            }
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmprspmsg;
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRespCode = "-1";
                tmpRespInfo = tmpStrRet[1];
            }
        } catch (Exception var16) {
            tmpRespCode = "-1";
            tmpRespInfo = var16.getMessage();
            var16.printStackTrace();
            this.WriteBankLogLn("查询明细异常:" + var16);
        }

        if ("-1".equals(tmpRespCode)) {
            retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
            retAtsTrans.writeStart();
            retAtsTrans.writeRespCode(tmpRespCode);
            retAtsTrans.writeRespInfo(tmpRespInfo);
        } else if (retAtsTrans.getWrittenRdCount() == 0) {
            retAtsTrans.writeRespInfo("交易为空");
            retAtsTrans.writeRespCode("0");
        }

        retAtsTrans.writeEnd();
        return retAtsTrans;
    }
}